/**
 * @param {string} text1
 * @param {string} text2
 * @return {number}
 */
var longestCommonSubsequence = function(text1, text2) {
    let len1 = text1.length, len2 = text2.length
    // dp[i][j] 前i个字符与前j个字符的最长公共子序列
    const dp = new Array(len1 + 1).fill().map(() => {
        return new Array(len2 + 1).fill(0)
    })
    for(let i = 0; i <= len1; i++) {
        for(let j = 0; j <= len2; j++) {
            if(text1[i] === text2[j]) dp[i + 1][j + 1] = dp[i][j] + 1
            else {
                dp[i + 1][j + 1] = Math.max(dp[i + 1][j], dp[i][j + 1])
            }
        }
    }
    return dp[m][n]
};